from tgext.zeroisp.model import *

class Hotel(DeclarativeBase):
    """Represent the settings for the membership of a user in a given team."""
    __tablename__ = 'hotel'
    hotel_id = Column(Integer, autoincrement=True, primary_key=True)
    post_id = Column(Integer,
                        ForeignKey('post.post_id'))
    star_rating = Column(Integer)
    price_from = Column(Float)
    hotel_room_number = Column(Integer)
    hotel_url = Column(Unicode(255))
    post = relation('Post', backref="hotel")

    @property
    def name(self):
        return self.post.post_title

    @property
    def address(self):
        return self.post.post_address.google_address

    @property
    def google_lat(self):
        return self.post.post_address.google_lat

    @property
    def google_lng(self):
        return self.post.post_address.google_lng


    @property
    def html_description(self):
        return "<div>%s</div>"%self.post.post_content

    def __jsonlist__(self):
        return ['country_name_code', 'country_name', 'administrative_area_name',
                'sub_administrative_area_name', 'locality_name',
                'id', 'name', 'url', 'star_rating', 'price_from', 'html_description',
                'google_address', 'google_lat', 'google_lng']

    def __json__(self):
        return {
                'id': self.hotel_id,
                'name': self.name,
                'url': self.hotel_url,
                'star_rating': self.star_rating,
                'price_from': self.price_from,
                'html_description': self.html_description,
                'country_name_code': self.post.post_address.country_name_code,
                'country_name': self.post.post_address.country_name,
                'administrative_area_name': self.post.post_address.administrative_area_name,
                'sub_administrative_area_name': self.post.post_address.sub_administrative_area_name,
                'locality_name' : self.post.post_address.locality_name,
                'google_lat': self.post.post_address.google_lat,
                'google_lng': self.post.post_address.google_lng,
                'google_address': self.post.post_address.google_address,
                }
